using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public interface ISimplyComponentData
{
    // public GameObject Obj { get; set; }
}

public interface ISimplySystem<in T> where T : ISimplyComponentData
{
    //public HashSet<T> ComponentSet { get; }
    public void AddComponentData(T componentData);

    public void RemoveComponentData(T componentData);
}


public class NullComponentData : ISimplyComponentData
{
}

public class SimplyNullSystem : ISimplySystem<NullComponentData>
{
    private HashSet<NullComponentData> _simplyNullData = new HashSet<NullComponentData>();

    public void AddComponentData(NullComponentData componentData)
    {
        _simplyNullData.Add(componentData);
    }

    public void RemoveComponentData(NullComponentData componentData)
    {
        _simplyNullData.Remove(componentData);
    }
}

public abstract class SimplyComponentData<T> : MonoBehaviour where T : ISimplyComponentData
{
    static HashSet<T> _values = new HashSet<T>();

    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    static void Clear()
    {
        _values.Clear();
    }
    //protected abstract ISimplySystem<T> SimplySystem { get; }
    protected abstract T self { get; }

    protected virtual void OnEnable()
    {
        //SimplySystem.AddComponentData(self);
        _values.Add(self);
    }

    protected virtual void OnDisable()
    {
        //SimplySystem.RemoveComponentData(self);
        _values.Remove(self);
    }

    public static IEnumerable<T> GetEnumerable()
    {
        return _values;
    }

    public static HashSet<T> GetHashSet() => _values;
}